# -*- coding: utf-8 -*-
import json
import random
import time

from django.http import JsonResponse
from django.views.decorators.csrf import csrf_exempt
from django import forms

from upload import settings
from uploadfile.models import Upload


# Create your views here.
class UserForm(forms.Form):
    filename = forms.FileField()


# 问诊页 最近医院
def getHospitalNearest(request):
    return JsonResponse({
        "code": 10000,
        "msg": "测试错误信息",
        "data": [
            {
                "geneHospitalCode": "1",
                "geneHospitalName": "合肥高新心血管病医院",
                "geneHospitalDescription": "特色科室: 心内科、神经内科、心内科、神经内科心内科、神经内科、神经内科、神经特色科室: 心内科、神经内科、心内科、神经内科心内科、神经内科、神经内科、神经…",
                "logo": "https://img1.baidu.com/it/u=1364104799,814302701&fm=11&fmt=auto&gp=0.jpg"
            }
        ]
    })


# 问诊也推荐科室 与 推荐医生
def getHospitalInfo(request):
    return JsonResponse({
        "code": 10000,
        "msg": "请求失败了个小舅子了",
        "data": {
            "hospitalIcon": "https://img1.baidu.com/it/u=1364104799,814302701&fm=11&fmt=auto&gp=0.jpg",
            "hospitalName": "合肥高新心血管病医院",
            "hospitalDes": "合肥高新心血管病医院是一家以心脑血管疾病治疗为主的大型三级专科医院，隶属于国内领先的医疗健康产业集团乐普医疗。集预防、治疗、急救、康复、教学、科研为一体，拥有国内一流的医疗技术、领先的专业医师团队、规范的医疗管理、可靠的医疗质量，为心脑血管疾病患者提供全方位诊疗服务。",
            "recommendDepartList": [{
                "departId": "1",
                "departName": "骨科111",
                "departDes": "鼻炎、中耳炎、鼻窦炎、咽炎、耳聋、耳鸣鼻炎、中耳炎、鼻窦炎、咽炎、耳聋、耳鸣",
                "departIcon": "https://img1.baidu.com/it/u=1364104799,814302701&fm=11&fmt=auto&gp=0.jpg"
            }, {
                "departId": "1",
                "departName": "骨科",
                "departDes": "鼻炎、中耳炎、鼻窦炎、咽炎、耳聋、耳鸣鼻炎、中耳炎、鼻窦炎、咽炎、耳聋、耳鸣",
                "departIcon": "https://img1.baidu.com/it/u=1364104799,814302701&fm=11&fmt=auto&gp=0.jpg"
            }, {
                "departId": "1",
                "departName": "骨科",
                "departDes": "鼻炎、中耳炎、鼻窦炎、咽炎、耳聋、耳鸣鼻炎、中耳炎、鼻窦炎、咽炎、耳聋、耳鸣",
                "departIcon": "https://img1.baidu.com/it/u=1364104799,814302701&fm=11&fmt=auto&gp=0.jpg"
            }, {
                "departId": "1",
                "departName": "骨科",
                "departDes": "鼻炎、中耳炎、鼻窦炎、咽炎、耳聋、耳鸣鼻炎、中耳炎、鼻窦炎、咽炎、耳聋、耳鸣",
                "departIcon": "https://img1.baidu.com/it/u=1364104799,814302701&fm=11&fmt=auto&gp=0.jpg"
            }, {
                "departId": "1",
                "departName": "骨科",
                "departDes": "鼻炎、中耳炎、鼻窦炎、咽炎、耳聋、耳鸣鼻炎、中耳炎、鼻窦炎、咽炎、耳聋、耳鸣",
                "departIcon": "https://img1.baidu.com/it/u=1364104799,814302701&fm=11&fmt=auto&gp=0.jpg"
            }, {
                "departId": "1",
                "departName": "骨科",
                "departDes": "鼻炎、中耳炎、鼻窦炎、咽炎、耳聋、耳鸣鼻炎、中耳炎、鼻窦炎、咽炎、耳聋、耳鸣",
                "departIcon": "https://img1.baidu.com/it/u=1364104799,814302701&fm=11&fmt=auto&gp=0.jpg"
            }, {
                "departId": "1",
                "departName": "骨科",
                "departDes": "鼻炎、中耳炎、鼻窦炎、咽炎、耳聋、耳鸣鼻炎、中耳炎、鼻窦炎、咽炎、耳聋、耳鸣",
                "departIcon": "https://img1.baidu.com/it/u=1364104799,814302701&fm=11&fmt=auto&gp=0.jpg"
            }, {
                "departId": "1",
                "departName": "骨科",
                "departDes": "鼻炎、中耳炎、鼻窦炎、咽炎、耳聋、耳鸣鼻炎、中耳炎、鼻窦炎、咽炎、耳聋、耳鸣",
                "departIcon": "https://img1.baidu.com/it/u=1364104799,814302701&fm=11&fmt=auto&gp=0.jpg"
            }, {
                "departId": "1",
                "departName": "骨科",
                "departDes": "鼻炎、中耳炎、鼻窦炎、咽炎、耳聋、耳鸣鼻炎、中耳炎、鼻窦炎、咽炎、耳聋、耳鸣",
                "departIcon": "https://img1.baidu.com/it/u=1364104799,814302701&fm=11&fmt=auto&gp=0.jpg"
            }, {
                "departId": "1",
                "departName": "骨科",
                "departDes": "鼻炎、中耳炎、鼻窦炎、咽炎、耳聋、耳鸣鼻炎、中耳炎、鼻窦炎、咽炎、耳聋、耳鸣",
                "departIcon": "https://img1.baidu.com/it/u=1364104799,814302701&fm=11&fmt=auto&gp=0.jpg"
            }, {
                "departId": "1",
                "departName": "骨科",
                "departDes": "鼻炎、中耳炎、鼻窦炎、咽炎、耳聋、耳鸣鼻炎、中耳炎、鼻窦炎、咽炎、耳聋、耳鸣",
                "departIcon": "https://img1.baidu.com/it/u=1364104799,814302701&fm=11&fmt=auto&gp=0.jpg"
            }, {
                "departId": "1",
                "departName": "骨科",
                "departDes": "鼻炎、中耳炎、鼻窦炎、咽炎、耳聋、耳鸣鼻炎、中耳炎、鼻窦炎、咽炎、耳聋、耳鸣",
                "departIcon": "https://img1.baidu.com/it/u=1364104799,814302701&fm=11&fmt=auto&gp=0.jpg"
            }, {
                "departId": "1",
                "departName": "骨科",
                "departDes": "鼻炎、中耳炎、鼻窦炎、咽炎、耳聋、耳鸣鼻炎、中耳炎、鼻窦炎、咽炎、耳聋、耳鸣",
                "departIcon": "https://img1.baidu.com/it/u=1364104799,814302701&fm=11&fmt=auto&gp=0.jpg"
            }],
            "recommendDoctorList": [{
                "doctorId": "1",
                "doctorName": "钟南山",
                "doctorSkill": "擅长领域：呼吸科感染性疾病、哮喘、慢性咳喘、支气管炎、慢性阻塞性肺疾病、哮慢性阻塞性肺疾病",
                "doctorIcon": "https://img2.baidu.com/it/u=4283224762,2640682880&fm=26&fmt=auto&gp=0.jpg",
                "doctorTitle": "主任医生",
                "minPrice": "88",
                "consultationTypes": ["视频", "图文"]
            }, {
                "doctorId": "1",
                "doctorName": "白求恩",
                "doctorSkill": "擅长领域：呼吸科感染性疾病、哮喘、慢性咳喘、支气管炎、慢性阻塞性肺疾病、哮慢性阻塞性肺疾病",
                "doctorIcon": "https://img0.baidu.com/it/u=1610086727,114363502&fm=26&fmt=auto&gp=0.jpg",
                "doctorTitle": "主任医生",
                "minPrice": "88",
                "consultationTypes": ["图文"]
            },
                {
                    "doctorId": "1",
                    "doctorName": "钟南山",
                    "doctorSkill": "擅长领域：呼吸科感染性疾病、哮喘、慢性咳喘、支气管炎、慢性阻塞性肺疾病、哮慢性阻塞性肺疾病",
                    "doctorIcon": "",
                    "doctorTitle": "主任医生",
                    "minPrice": "88",
                    "consultationTypes": ["视频", "图文"]
                },
                {
                    "doctorId": "1",
                    "doctorName": "钟南山",
                    "doctorSkill": "擅长领域：呼吸科感染性疾病、哮喘、慢性咳喘、支气管炎、慢性阻塞性肺疾病、哮慢性阻塞性肺疾病",
                    "doctorIcon": "https://img1.baidu.com/it/u=1364104799,814302701&fm=11&fmt=auto&gp=0.jpg",
                    "doctorTitle": "主任医生",
                    "minPrice": "88",
                    "consultationTypes": ["视频", "图文"]
                },
                {
                    "doctorId": "1",
                    "doctorName": "钟南山",
                    "doctorSkill": "擅长领域：呼吸科感染性疾病、哮喘、慢性咳喘、支气管炎、慢性阻塞性肺疾病、哮慢性阻塞性肺疾病",
                    "doctorIcon": "https://img1.baidu.com/it/u=1364104799,814302701&fm=11&fmt=auto&gp=0.jpg",
                    "doctorTitle": "主任医生",
                    "minPrice": "88",
                    "consultationTypes": ["视频", "图文"]
                }, {
                    "doctorId": "1",
                    "doctorName": "钟南山",
                    "doctorSkill": "擅长领域：呼吸科感染性疾病、哮喘、慢性咳喘、支气管炎、慢性阻塞性肺疾病、哮慢性阻塞性肺疾病",
                    "doctorIcon": "https://img1.baidu.com/it/u=1364104799,814302701&fm=11&fmt=auto&gp=0.jpg",
                    "doctorTitle": "主任医生",
                    "minPrice": "88",
                    "consultationTypes": ["视频", "图文"]
                }
            ]
        }
    })


# 问诊时间
def isOnLine(request):
    return createSuccessResult({
        "isOnLine": False,
        "onlineTime": "上午 8:00～12:00\n下午 13:30~1700\n晚上 19:00～22:00"
    })


# 检查检验单列表
def getCheckInspectList(request):
    return JsonResponse({
        "code": 10000,
        "msg": "哎 我出错了啊",
        "data": [{
            "examinationName": "检查",
            "examinationTime": "2020.02.22",
            "examinationDes": "多普勒心脏超声彩超",
            "examinationDoctor": "医生：张三 主任医师 消化内科 北京乐普互联网医院",
            "examinationState": "未完成",
            "examinationId": "1231232323232"
        }, {
            "examinationName": "检验",
            "examinationTime": "2020.02.22",
            "examinationDes": "多普勒心脏超声彩超",
            "examinationDoctor": "医生：张三 主任医师 消化内科 北京乐普互联网医院",
            "examinationState": "未完成",
            "examinationId": "1231232323232"
        }, {
            "examinationName": "检查",
            "examinationTime": "2020.02.22",
            "examinationDes": "多普勒心脏超声彩超",
            "examinationDoctor": "医生：张三 主任医师 消化内科 北京乐普互联网医院张三 主任医师 消化内科 北京乐普互联网医院",
            "examinationState": "已完成",
            "examinationId": "1231232323232"
        }, {
            "examinationName": "检查",
            "examinationTime": "2020.02.22",
            "examinationDes": "多普勒心脏超声彩超",
            "examinationDoctor": "医生：张三 主任医师 消化内科 北京乐普互联网医院",
            "examinationState": "已完成",
            "examinationId": "1231232323232"
        }]
    })


def getDoctorHomeInfo(request):
    return JsonResponse({
        "code": 10000,
        "msg": "success",
        "data": {
            "hospitalName": "北京市朝阳医院",
            "doctorId": "1",
            "hospitalId": "1",
            "doctorName": "张三",
            "doctorIcon": "https://img0.baidu.com/it/u=3311900507,1448170316&fm=26&fmt=auto&gp=0.jpg",
            "doctorTitle": "主任医师",
            "doctorInfo": "1987年从北京医科大学毕业后，一直在北京1987年从北京医科大学毕业后，一直在北京1987年从北京医科大学毕业后，一直在北京1987年从北京医科大学毕业后，一直在北京积水潭医院创伤骨科工作，2004年晋升为主任医师，2007年晋升为北京大学医学部教授。先后在美国，英国，德国，瑞士，新加坡，韩国等国家进行学习和会议交流，对创伤骨科领域的常见病，疑难病有丰富的临床治疗经验，尤其对骨盆髋臼骨折的治疗有很深的造诣，先后获得国家科技进步二等奖1项，中华医学科技一等奖、三等奖各1项，北京市科技进步二等奖1项。",
            "skillDes": "脊柱创伤，退行性疾病，脊柱畸形的诊脊柱创伤，退行性疾病，脊柱畸形的诊脊柱创伤，退行性疾病，脊柱畸形的诊脊柱创伤，退行性疾病，脊柱畸形的诊脊柱创伤，退行性疾病，脊柱畸形的诊脊柱创伤，退行性疾病，脊柱畸形的诊脊柱创伤，退行性疾病，脊柱畸形的诊脊柱创伤，退行性疾病，脊柱畸形的诊",
            "deptList": [
                {
                    "departName": "骨科",
                    "departId": "1",
                    "doctorLevel": "专家号",
                    "consultationsList": [
                        {
                            "consultationType": "视频",
                            "consultationList": [
                                {
                                    "type": "急速",
                                    "consultationDiscountMoney": "11.9",
                                    "consultationOriginMoney": "59.9",
                                    "useCoupons": "true"
                                }, {
                                    "type": "普通",
                                    "consultationDiscountMoney": "29.9",
                                    "consultationOriginMoney": "100",
                                    "useCoupons": "true"
                                }, {
                                    "type": "预约",
                                    "consultationDiscountMoney": "88888",
                                    "consultationOriginMoney": "99999",
                                    "useCoupons": "true"
                                }
                            ]
                        },
                        {
                            "consultationType": "图文",
                            "consultationList": [
                                {
                                    "type": "急速",
                                    "consultationDiscountMoney": "29.9",
                                    "consultationOriginMoney": "100",
                                    "useCoupons": "true"
                                }, {
                                    "type": "预约",
                                    "consultationDiscountMoney": "29.9",
                                    "consultationOriginMoney": "100",
                                    "useCoupons": "true"
                                }
                            ]
                        }
                    ]
                },
                {
                    "departName": "内科",
                    "departId": "2",
                    "doctorLevel": "普通号",
                    "consultationsList": [
                        {
                            "consultationType": "视频",
                            "consultationList": [
                                {
                                    "type": "急速",
                                    "consultationDiscountMoney": "29.9",
                                    "consultationOriginMoney": "100",
                                    "useCoupons": "true"
                                }, {
                                    "type": "普通",
                                    "consultationDiscountMoney": "29.9",
                                    "consultationOriginMoney": "100",
                                    "useCoupons": "true"
                                }, {
                                    "type": "预约",
                                    "consultationDiscountMoney": "29.9",
                                    "consultationOriginMoney": "100",
                                    "useCoupons": "true"
                                }
                            ]
                        },
                        {
                            "consultationType": "图文",
                            "consultationList": [
                                {
                                    "type": "急速",
                                    "consultationDiscountMoney": "29.9",
                                    "consultationOriginMoney": "100",
                                    "useCoupons": "true"
                                }, {
                                    "type": "预约",
                                    "consultationDiscountMoney": "29.9",
                                    "consultationOriginMoney": "100",
                                    "useCoupons": "false"
                                }
                            ]
                        }
                    ]
                }

            ]
        }
    })


def getDepartHomeInfo(request):
    return createSuccessResult({
        "depName": "北京市朝阳医院",
        "depId": "1",
        "hospitalId": "1",
        "depIcon": "https://img0.baidu.com/it/u=3311900507,1448170316&fm=26&fmt=auto&gp=0.jpg",
        "depDes": "常见病症：中风、支气管炎、贫血、皮肤过敏、缺铁性贫血、酒精中毒、代谢性酸中毒、亚-斯氏综合征..",
        "doctorTitleLevelList": [{
            "doctorLevel": "专家号",
            "consultationsList": [{
                "consultationType": "视频",
                "consultationList": [{
                    "type": "急速",
                    "consultationDiscountMoney": "11.9",
                    "consultationOriginMoney": "59.9",
                    "useCoupons": "true"
                }, {
                    "type": "普通",
                    "consultationDiscountMoney": "29.9",
                    "consultationOriginMoney": "100",
                    "useCoupons": "true"
                }, {
                    "type": "预约",
                    "consultationDiscountMoney": "19999.80",
                    "consultationOriginMoney": "20000",
                    "useCoupons": "true"
                }]
            },
                {
                    "consultationType": "图文",
                    "consultationList": [{
                        "type": "急速",
                        "consultationDiscountMoney": "29.9",
                        "consultationOriginMoney": "100",
                        "useCoupons": "true"
                    }, {
                        "type": "预约",
                        "consultationDiscountMoney": "29.9",
                        "consultationOriginMoney": "100",
                        "useCoupons": "true"
                    }]
                }
            ]
        },
            {

                "doctorLevel": "普通号",
                "consultationsList": [{
                    "consultationType": "视频",
                    "consultationList": [{
                        "type": "急速",
                        "consultationDiscountMoney": "29.9",
                        "consultationOriginMoney": "100",
                        "useCoupons": "true"
                    }, {
                        "type": "普通",
                        "consultationDiscountMoney": "29.9",
                        "consultationOriginMoney": "100",
                        "useCoupons": "true"
                    }, {
                        "type": "预约",
                        "consultationDiscountMoney": "29.9",
                        "consultationOriginMoney": "100",
                        "useCoupons": "true"
                    }]
                },
                    {
                        "consultationType": "图文",
                        "consultationList": [{
                            "type": "急速",
                            "consultationDiscountMoney": "29.9",
                            "consultationOriginMoney": "100",
                            "useCoupons": "true"
                        }, {
                            "type": "预约",
                            "consultationDiscountMoney": "29.9",
                            "consultationOriginMoney": "100",
                            "useCoupons": "false"
                        }]
                    }
                ]
            }
        ]
    })


# 科室主页--推荐医生
def getDepartRecommendDoctors(request):
    resultList = []
    dataCount = 0
    pageIndex = int(request.GET.get("pageIndex"))
    if pageIndex <= 1:
        dataCount = 10
    else:
        dataCount = 2
    for i in range(0, dataCount):
        resultList.append({
            "depId": random.random(),
            "doctorId": random.random(),
            "doctorName": "终南山",
            "doctorIcon": "https://img1.baidu.com/it/u=535726382,4210743894&fm=26&fmt=auto&gp=0.jpg",
            "doctorTitle": "主任医生",
            "doctorLevel": "专家号",
            "skillDes": "擅长领域：呼吸科感染性疾病、哮喘、慢性咳喘、支气管炎、慢性阻塞性肺疾病、慢性咳喘..",
            "consultationsList": [{
                "consultationType": "视频",
                "consultationList": [{
                    "type": "急速",
                    "consultationDiscountMoney": "11.9",
                    "consultationOriginMoney": "59.9",
                    "useCoupons": "true"
                }, {
                    "type": "普通",
                    "consultationDiscountMoney": "29.9",
                    "consultationOriginMoney": "100",
                    "useCoupons": "true"
                }, {
                    "type": "预约",
                    "consultationDiscountMoney": "199.8",
                    "consultationOriginMoney": "200",
                    "useCoupons": "true"
                }]
            },
                {
                    "consultationType": "图文",
                    "consultationList": [{
                        "type": "急速",
                        "consultationDiscountMoney": "29.9",
                        "consultationOriginMoney": "100",
                        "useCoupons": "true"
                    }]
                }
            ]
        })
    return createSuccessResult(resultList)


# 创建成功结果
def createSuccessResult(data):
    result = {}
    result.setdefault("code", 10000)
    result.setdefault("msg", "success")
    result.setdefault("data", data)
    return JsonResponse(result)


# 创建失败结果
def createFailResult(data):
    result = {}
    result.setdefault("code", 10000)
    result.setdefault("msg", "请求成功")
    result.setdefault("data", data)
    return result


def getDepartments(request):
    time.sleep(4)
    return JsonResponse({
        "code": 10000,
        "msg": "success",
        "data": [
            {
                "onlineDeptCode": "1",
                "onlineDeptName": "骨科",
                "onlineDeptShorter": "鼻炎、中耳炎、鼻窦炎、咽炎、耳聋、耳鸣鼻炎、中耳炎、鼻窦炎、咽炎、耳聋、耳鸣",
                "onlineDeptIcon": "https://img1.baidu.com/it/u=1364104799,814302701&fm=11&fmt=auto&gp=0.jpg"
            },
            {
                "onlineDeptCode": "1",
                "onlineDeptName": "骨科",
                "onlineDeptShorter": "鼻炎、中耳炎、鼻窦炎、咽炎、耳聋、耳鸣鼻炎、中耳炎、鼻窦炎、咽炎、耳聋、耳鸣",
                "onlineDeptIcon": "https://img1.baidu.com/it/u=1364104799,814302701&fm=11&fmt=auto&gp=0.jpg"
            }, {
                "onlineDeptCode": "1",
                "onlineDeptName": "骨科",
                "onlineDeptShorter": "鼻炎、中耳炎、鼻窦炎、咽炎、耳聋、耳鸣鼻炎、中耳炎、鼻窦炎、咽炎、耳聋、耳鸣",
                "onlineDeptIcon": "https://img1.baidu.com/it/u=1364104799,814302701&fm=11&fmt=auto&gp=0.jpg"
            }, {
                "onlineDeptCode": "1",
                "onlineDeptName": "骨科",
                "onlineDeptShorter": "鼻炎、中耳炎、鼻窦炎、咽炎、耳聋、耳鸣鼻炎、中耳炎、鼻窦炎、咽炎、耳聋、耳鸣",
                "onlineDeptIcon": "https://img1.baidu.com/it/u=1364104799,814302701&fm=11&fmt=auto&gp=0.jpg"
            }, {
                "onlineDeptCode": "1",
                "onlineDeptName": "骨科",
                "onlineDeptShorter": "鼻炎、中耳炎、鼻窦炎、咽炎、耳聋、耳鸣鼻炎、中耳炎、鼻窦炎、咽炎、耳聋、耳鸣",
                "onlineDeptIcon": "https://img1.baidu.com/it/u=1364104799,814302701&fm=11&fmt=auto&gp=0.jpg"
            }, {
                "onlineDeptCode": "1",
                "onlineDeptName": "骨科",
                "onlineDeptShorter": "鼻炎、中耳炎、鼻窦炎、咽炎、耳聋、耳鸣鼻炎、中耳炎、鼻窦炎、咽炎、耳聋、耳鸣",
                "onlineDeptIcon": "https://img1.baidu.com/it/u=1364104799,814302701&fm=11&fmt=auto&gp=0.jpg"
            }, {
                "onlineDeptCode": "1",
                "onlineDeptName": "骨科",
                "onlineDeptShorter": "鼻炎、中耳炎、鼻窦炎、咽炎、耳聋、耳鸣鼻炎、中耳炎、鼻窦炎、咽炎、耳聋、耳鸣",
                "onlineDeptIcon": "https://img1.baidu.com/it/u=1364104799,814302701&fm=11&fmt=auto&gp=0.jpg"
            }, {
                "onlineDeptCode": "1",
                "onlineDeptName": "骨科",
                "onlineDeptShorter": "鼻炎、中耳炎、鼻窦炎、咽炎、耳聋、耳鸣鼻炎、中耳炎、鼻窦炎、咽炎、耳聋、耳鸣",
                "onlineDeptIcon": "https://img1.baidu.com/it/u=1364104799,814302701&fm=11&fmt=auto&gp=0.jpg"
            }, {
                "onlineDeptCode": "1",
                "onlineDeptName": "骨科",
                "onlineDeptShorter": "鼻炎、中耳炎、鼻窦炎、咽炎、耳聋、耳鸣鼻炎、中耳炎、鼻窦炎、咽炎、耳聋、耳鸣",
                "onlineDeptIcon": "https://img1.baidu.com/it/u=1364104799,814302701&fm=11&fmt=auto&gp=0.jpg"
            }, {
                "onlineDeptCode": "1",
                "onlineDeptName": "骨科",
                "onlineDeptShorter": "鼻炎、中耳炎、鼻窦炎、咽炎、耳聋、耳鸣鼻炎、中耳炎、鼻窦炎、咽炎、耳聋、耳鸣",
                "onlineDeptIcon": "https://img1.baidu.com/it/u=1364104799,814302701&fm=11&fmt=auto&gp=0.jpg"
            },
        ]
    })


def getDoctors(request):
    result = {}
    for i in range(0, 6):
        result.setdefault({
            "doctorId": "1",
            "doctorName": "钟南山",
            "doctorSkill": "擅长领域：呼吸科感染性疾病、哮喘、慢性咳喘、支气管炎、慢性阻塞性肺疾病、哮慢性阻塞性肺疾病",
            "doctorIcon": "https://img1.baidu.com/it/u=1364104799,814302701&fm=11&fmt=auto&gp=0.jpg",
            "doctorTitle": "主任医生",
            "minPrice": "88",
            "consultationTypes": ["视频", "图文"]
        })
    return createSuccessResult(result)


def getCheckOrderDetail(request):
    return JsonResponse({
        "code": 10000,
        "msg": "success",
        "data": {
            "patientId": "111",
            "userId": "111",
            "checkId": "111",
            "status": "未完成",
            "checkItem": "多普勒超声心脏彩超",
            "attention": "医生建议医生建议医生建议医生建议医生建议医生建议医生建议医生建议医生建议医生建议",
            "picturesList": ["https://img0.baidu.com/it/u=1242053365,2901037121&fm=26&fmt=auto&gp=0.jpg",
                             "https://img1.baidu.com/it/u=1364104799,814302701&fm=11&fmt=auto&gp=0.jpg",
                             "https://img0.baidu.com/it/u=1242053365,2901037121&fm=26&fmt=auto&gp=0.jpg",
                             "https://img1.baidu.com/it/u=1364104799,814302701&fm=11&fmt=auto&gp=0.jpg",
                             "https://img1.baidu.com/it/u=1364104799,814302701&fm=11&fmt=auto&gp=0.jpg",
                             "https://img1.baidu.com/it/u=1364104799,814302701&fm=11&fmt=auto&gp=0.jpg"]
        }
    })


def getHistoryMessage(request):
    sender = "MID1415134857525047298431"
    reciver = "lisi"
    return JsonResponse({
        "code": 10000,
        "msg": "success",
        "data": [
            {
                "clientTime": 1627032907,
                "serverTime": 1627032908,
                "seq": 82995908,
                "isMessageSender": True,
                "messageStatus": 2,
                "messageType": 2,
                "msgID": "144115261247181295-1627032907-3212347662",
                "receiverUserID": reciver,
                "senderUserID": sender,
                "messageBaseElements": {
                    "data": "{\"type\":100001,\"content\":\"问诊开始\"}",
                    "elementType": 2
                }
            },
            {
                "clientTime": 1627032907,
                "serverTime": 1627032908,
                "seq": 82995908,
                "isMessageSender": True,
                "messageStatus": 2,
                "messageType": 6,
                "msgID": "144115261247181295-1627032907-3212347662",
                "receiverUserID": reciver,
                "senderUserID": sender,
                "messageBaseElements": {
                    "elementType": 6,
                    "fileDownloadUrl": "https://cos.ap-shanghai.myqcloud.com/6d84-shanghai-007-shared-09-1256635546/6775-1400527812/6860-yq/ea85a1eca7090e10bb0659ccad73ce6b.pdf",
                    "fileName": "测试pdf文件11名.pdf",
                    "fileSize": 141043,
                    "fileUUID": "3400527812_yq_ea85a1eca7090e10bb0659ccad73ce6b.pdf"
                }
            }
            ,
            {
                "clientTime": 1627032907,
                "serverTime": 1627032908,
                "seq": 82995908,
                "isMessageSender": True,
                "messageStatus": 2,
                "messageType": 1,
                "msgID": "144115261247181295-1627032907-3212347662",
                "receiverUserID": reciver,
                "senderUserID": sender,
                "messageBaseElements": {
                    "textContent": "文本内容",
                    "elementType": 1
                }
            },
            {
                "clientTime": 1627032907,
                "serverTime": 1627032908,
                "seq": 82995908,
                "isMessageSender": True,
                "messageStatus": 2,
                "messageType": 2,
                "msgID": "144115261247181295-1627032907-3212347662",
                "receiverUserID": reciver,
                "senderUserID": sender,
                "messageBaseElements": {
                    "data": "{\"type\":100002,\"content\":\"{\\\"adviseId\\\":1,\\\"title\\\":\\\"建议用药\\\",\\\"drugs\\\":[{\\\"drugName\\\":\\\"而被善谈胶囊\\\",\\\"usage\\\":\\\"10mg * 5片\\\",\\\"count\\\":\\\"2\\\"},{\\\"drugName\\\":\\\"而被善谈胶囊\\\",\\\"usage\\\":\\\"10mg * 5片\\\",\\\"count\\\":\\\"2\\\"},{\\\"drugName\\\":\\\"而被善谈胶囊\\\",\\\"usage\\\":\\\"10mg * 5片\\\",\\\"count\\\":\\\"2\\\"},{\\\"drugName\\\":\\\"而被善谈胶囊\\\",\\\"usage\\\":\\\"10mg * 5片\\\",\\\"count\\\":\\\"2\\\"},{\\\"drugName\\\":\\\"而被善谈胶囊\\\",\\\"usage\\\":\\\"10mg * 5片\\\",\\\"count\\\":\\\"2\\\"}]}\"}",
                    "elementType": 2
                }
            },
            {
                "clientTime": 1627032907,
                "serverTime": 1627032908,
                "seq": 82995908,
                "isMessageSender": True,
                "messageStatus": 2,
                "messageType": 2,
                "msgID": "144115261247181295-1627032907-3212347662",
                "receiverUserID": reciver,
                "senderUserID": sender,
                "messageBaseElements": {
                    "data": "{\"type\":100003,\"content\":\"{\\\"title\\\":\\\"检查\\\",\\\"details\\\":\\\"我是检查单详情啊\\\"}\"}",
                    "elementType": 2
                }
            }, {
                "clientTime": 1627032907,
                "serverTime": 1627032908,
                "seq": 82995908,
                "isMessageSender": True,
                "messageStatus": 2,
                "messageType": 2,
                "msgID": "144115261247181295-1627032907-3212347662",
                "receiverUserID": reciver,
                "senderUserID": sender,
                "messageBaseElements": {
                    "data": "{\"type\":100004,\"content\":\"{\\\"doctorAdvise\\\":\\\"医生建议：建议内容建议内容建议内容建议内容建议内容建议内容建议内容建议内容建议内容建议内容建议内容建议内容\\\"}\"}",
                    "elementType": 2
                }
            }, {
                "clientTime": 1627032907,
                "serverTime": 1627032908,
                "seq": 82995908,
                "isMessageSender": True,
                "messageStatus": 2,
                "messageType": 2,
                "msgID": "144115261247181295-1627032907-3212347662",
                "receiverUserID": reciver,
                "senderUserID": sender,
                "messageBaseElements": {
                    "data": "{\"type\":100004,\"content\":\"{\\\"doctorAdvise\\\":\\\"医生建议：建议内容建议内容建议内容建议内容建议内容建议内容建议内容建议内容建议内容建议内容建议内容建议内容\\\"}\"}",
                    "elementType": 2
                }
            }, {
                "clientTime": 1627032907,
                "serverTime": 1627032908,
                "seq": 82995908,
                "isMessageSender": True,
                "messageStatus": 2,
                "messageType": 2,
                "msgID": "144115261247181295-1627032907-3212347662",
                "receiverUserID": reciver,
                "senderUserID": sender,
                "messageBaseElements": {
                    "data": "{\"type\":100004,\"content\":\"{\\\"doctorAdvise\\\":\\\"医生建议：建议内容建议内容建议内容建议内容建议内容建议内容建议内容建议内容建议内容建议内容建议内容建议内容\\\"}\"}",
                    "elementType": 2
                }
            }, {
                "clientTime": 1627032907,
                "serverTime": 1627032908,
                "seq": 82995908,
                "isMessageSender": True,
                "messageStatus": 2,
                "messageType": 2,
                "msgID": "144115261247181295-1627032907-3212347662",
                "receiverUserID": reciver,
                "senderUserID": sender,
                "messageBaseElements": {
                    "data": "{\"type\":100004,\"content\":\"{\\\"doctorAdvise\\\":\\\"医生建议：建议内容建议内容建议内容建议内容建议内容建议内容建议内容建议内容建议内容建议内容建议内容建议内容\\\"}\"}",
                    "elementType": 2
                }
            }, {
                "clientTime": 1627032907,
                "serverTime": 1627032908,
                "seq": 82995908,
                "isMessageSender": True,
                "messageStatus": 2,
                "messageType": 2,
                "msgID": "144115261247181295-1627032907-3212347662",
                "receiverUserID": reciver,
                "senderUserID": sender,
                "messageBaseElements": {
                    "data": "{\"type\":100004,\"content\":\"{\\\"doctorAdvise\\\":\\\"医生建议：建议内容建议内容建议内容建议内容建议内容建议内容建议内容建议内容建议内容建议内容建议内容建议内容\\\"}\"}",
                    "elementType": 2
                }
            }, {
                "clientTime": 1627032907,
                "serverTime": 1627032908,
                "seq": 82995908,
                "isMessageSender": True,
                "messageStatus": 2,
                "messageType": 2,
                "msgID": "144115261247181295-1627032907-3212347662",
                "receiverUserID": reciver,
                "senderUserID": sender,
                "messageBaseElements": {
                    "data": "{\"type\":100004,\"content\":\"{\\\"doctorAdvise\\\":\\\"医生建议：建议内容建议内容建议内容建议内容建议内容建议内容建议内容建议内容建议内容建议内容建议内容建议内容\\\"}\"}",
                    "elementType": 2
                }
            }, {
                "clientTime": 1627032907,
                "serverTime": 1627032908,
                "seq": 82995908,
                "isMessageSender": True,
                "messageStatus": 2,
                "messageType": 2,
                "msgID": "144115261247181295-1627032907-3212347662",
                "receiverUserID": reciver,
                "senderUserID": sender,
                "messageBaseElements": {
                    "data": "{\"type\":100004,\"content\":\"{\\\"doctorAdvise\\\":\\\"医生建议：建议内容建议内容建议内容建议内容建议内容建议内容建议内容建议内容建议内容建议内容建议内容建议内容\\\"}\"}",
                    "elementType": 2
                }
            }, {
                "clientTime": 1627032907,
                "serverTime": 1627032908,
                "seq": 82995908,
                "isMessageSender": True,
                "messageStatus": 2,
                "messageType": 2,
                "msgID": "144115261247181295-1627032907-3212347662",
                "receiverUserID": reciver,
                "senderUserID": sender,
                "messageBaseElements": {
                    "data": "{\"type\":100004,\"content\":\"{\\\"doctorAdvise\\\":\\\"医生建议：建议内容建议内容建议内容建议内容建议内容建议内容建议内容建议内容建议内容建议内容建议内容建议内容\\\"}\"}",
                    "elementType": 2
                }
            }, {
                "clientTime": 1627032907,
                "serverTime": 1627032908,
                "seq": 82995908,
                "isMessageSender": True,
                "messageStatus": 2,
                "messageType": 2,
                "msgID": "144115261247181295-1627032907-3212347662",
                "receiverUserID": reciver,
                "senderUserID": sender,
                "messageBaseElements": {
                    "data": "{\"type\":100004,\"content\":\"{\\\"doctorAdvise\\\":\\\"医生建议：建议内容建议内容建议内容建议内容建议内容建议内容建议内容建议内容建议内容建议内容建议内容建议内容\\\"}\"}",
                    "elementType": 2
                }
            }, {
                "clientTime": 1627032907,
                "serverTime": 1627032908,
                "seq": 82995908,
                "isMessageSender": True,
                "messageStatus": 2,
                "messageType": 2,
                "msgID": "144115261247181295-1627032907-3212347662",
                "receiverUserID": reciver,
                "senderUserID": sender,
                "messageBaseElements": {
                    "data": "{\"type\":100004,\"content\":\"{\\\"doctorAdvise\\\":\\\"医生建议：建议内容建议内容建议内容建议内容建议内容建议内容建议内容建议内容建议内容建议内容建议内容建议内容\\\"}\"}",
                    "elementType": 2
                }
            }, {
                "clientTime": 1627032907,
                "serverTime": 1627032908,
                "seq": 82995908,
                "isMessageSender": True,
                "messageStatus": 2,
                "messageType": 2,
                "msgID": "144115261247181295-1627032907-3212347662",
                "receiverUserID": reciver,
                "senderUserID": sender,
                "messageBaseElements": {
                    "data": "{\"type\":100004,\"content\":\"{\\\"doctorAdvise\\\":\\\"医生建议：建议内容建议内容建议内容建议内容建议内容建议内容建议内容建议内容建议内容建议内容建议内容建议内容\\\"}\"}",
                    "elementType": 2
                }
            }, {
                "clientTime": 1627032907,
                "serverTime": 1627032908,
                "seq": 82995908,
                "isMessageSender": True,
                "messageStatus": 2,
                "messageType": 2,
                "msgID": "144115261247181295-1627032907-3212347662",
                "receiverUserID": reciver,
                "senderUserID": sender,
                "messageBaseElements": {
                    "data": "{\"type\":100004,\"content\":\"{\\\"doctorAdvise\\\":\\\"医生建议：建议内容建议内容建议内容建议内容建议内容建议内容建议内容建议内容建议内容建议内容建议内容建议内容\\\"}\"}",
                    "elementType": 2
                }
            }, {
                "clientTime": 1627032907,
                "serverTime": 1627032908,
                "seq": 82995908,
                "isMessageSender": True,
                "messageStatus": 2,
                "messageType": 2,
                "msgID": "144115261247181295-1627032907-3212347662",
                "receiverUserID": reciver,
                "senderUserID": sender,
                "messageBaseElements": {
                    "data": "{\"type\":100004,\"content\":\"{\\\"doctorAdvise\\\":\\\"医生建议：建议内容建议内容建议内容建议内容建议内容建议内容建议内容建议内容建议内容建议内容建议内容建议内容\\\"}\"}",
                    "elementType": 2
                }
            }, {
                "clientTime": 1627032907,
                "serverTime": 1627032908,
                "seq": 82995908,
                "isMessageSender": True,
                "messageStatus": 2,
                "messageType": 2,
                "msgID": "144115261247181295-1627032907-3212347662",
                "receiverUserID": reciver,
                "senderUserID": sender,
                "messageBaseElements": {
                    "data": "{\"type\":100004,\"content\":\"{\\\"doctorAdvise\\\":\\\"医生建议：建议内容建议内容建议内容建议内容建议内容建议内容建议内容建议内容建议内容建议内容建议内容建议内容\\\"}\"}",
                    "elementType": 2
                }
            }, {
                "clientTime": 1627032907,
                "serverTime": 1627032908,
                "seq": 82995908,
                "isMessageSender": True,
                "messageStatus": 2,
                "messageType": 2,
                "msgID": "144115261247181295-1627032907-3212347662",
                "receiverUserID": reciver,
                "senderUserID": sender,
                "messageBaseElements": {
                    "data": "{\"type\":100004,\"content\":\"{\\\"doctorAdvise\\\":\\\"医生建议：建议内容建议内容建议内容建议内容建议内容建议内容建议内容建议内容建议内容建议内容建议内容建议内容\\\"}\"}",
                    "elementType": 2
                }
            }, {
                "clientTime": 1627032907,
                "serverTime": 1627032908,
                "seq": 82995908,
                "isMessageSender": True,
                "messageStatus": 2,
                "messageType": 2,
                "msgID": "144115261247181295-1627032907-3212347662",
                "receiverUserID": reciver,
                "senderUserID": sender,
                "messageBaseElements": {
                    "data": "{\"type\":100004,\"content\":\"{\\\"doctorAdvise\\\":\\\"医生建议：建议内容建议内容建议内容建议内容建议内容建议内容建议内容建议内容建议内容建议内容建议内容建议内容\\\"}\"}",
                    "elementType": 2
                }
            }, {
                "clientTime": 1627032907,
                "serverTime": 1627032908,
                "seq": 82995908,
                "isMessageSender": True,
                "messageStatus": 2,
                "messageType": 2,
                "msgID": "144115261247181295-1627032907-3212347662",
                "receiverUserID": reciver,
                "senderUserID": sender,
                "messageBaseElements": {
                    "data": "{\"type\":100004,\"content\":\"{\\\"doctorAdvise\\\":\\\"医生建议：建议内容建议内容建议内容建议内容建议内容建议内容建议内容建议内容建议内容建议内容建议内容建议内容\\\"}\"}",
                    "elementType": 2
                }
            }, {
                "clientTime": 1627032907,
                "serverTime": 1627032908,
                "seq": 82995908,
                "isMessageSender": True,
                "messageStatus": 2,
                "messageType": 2,
                "msgID": "144115261247181295-1627032907-3212347662",
                "receiverUserID": reciver,
                "senderUserID": sender,
                "messageBaseElements": {
                    "data": "{\"type\":100004,\"content\":\"{\\\"doctorAdvise\\\":\\\"医生建议：建议内容建议内容建议内容建议内容建议内容建议内容建议内容建议内容建议内容建议内容建议内容建议内容\\\"}\"}",
                    "elementType": 2
                }
            }, {
                "clientTime": 1627032907,
                "serverTime": 1627032908,
                "seq": 82995908,
                "isMessageSender": True,
                "messageStatus": 2,
                "messageType": 2,
                "msgID": "144115261247181295-1627032907-3212347662",
                "receiverUserID": reciver,
                "senderUserID": sender,
                "messageBaseElements": {
                    "data": "{\"type\":100004,\"content\":\"{\\\"doctorAdvise\\\":\\\"医生建议：建议内容建议内容建议内容建议内容建议内容建议内容建议内容建议内容建议内容建议内容建议内容建议内容\\\"}\"}",
                    "elementType": 2
                }
            }, {
                "clientTime": 1627032907,
                "serverTime": 1627032908,
                "seq": 82995908,
                "isMessageSender": True,
                "messageStatus": 2,
                "messageType": 2,
                "msgID": "144115261247181295-1627032907-3212347662",
                "receiverUserID": reciver,
                "senderUserID": sender,
                "messageBaseElements": {
                    "data": "{\"type\":100004,\"content\":\"{\\\"doctorAdvise\\\":\\\"医生建议：建议内容建议内容建议内容建议内容建议内容建议内容建议内容建议内容建议内容建议内容建议内容建议内容\\\"}\"}",
                    "elementType": 2
                }
            },
            {
                "clientTime": 1627032907,
                "serverTime": 1627032908,
                "seq": 82995908,
                "isMessageSender": True,
                "messageStatus": 2,
                "messageType": 2,
                "msgID": "144115261247181295-1627032907-3212347662",
                "receiverUserID": reciver,
                "senderUserID": sender,
                "messageBaseElements": {
                    "data": "{\"type\":100001,\"content\":\"问诊开始\"}",
                    "elementType": 2
                }
            },
            {
                "clientTime": 1627032907,
                "serverTime": 1627032908,
                "seq": 82995908,
                "isMessageSender": True,
                "messageStatus": 2,
                "messageType": 3,
                "msgID": "144115261247181295-1627032907-3212347662",
                "receiverUserID": reciver,
                "senderUserID": sender,
                "messageBaseElements": {
                    "elementType": 3,
                    "thumbImageWidth": 198,
                    "thumbImageHeight": 405,
                    "thumbImageUrl": "https://cos.ap-shanghai.myqcloud.com/6d84-shanghai-007-shared-09-1256635546/6775-1400527812/6860-yq/3b7faacdd4eca5012cf29ab7afae4668.png?imageView2/3/w/198/h/198",
                    "originImageWidth": 1176,
                    "originImageHeight": 2400,
                    "originImageUrl": "https://cos.ap-shanghai.myqcloud.com/6d84-shanghai-007-shared-09-1256635546/6775-1400527812/6860-yq/3b7faacdd4eca5012cf29ab7afae4668.png?imageMogr2/",
                    "largeImageWidth": 720,
                    "largeImageHeight": 1469,
                    "largeImageUrl": "https://cos.ap-shanghai.myqcloud.com/6d84-shanghai-007-shared-09-1256635546/6775-1400527812/6860-yq/3b7faacdd4eca5012cf29ab7afae4668.png?imageView2/3/w/720/h/720"
                }
            }, {
                "clientTime": 1627032907,
                "serverTime": 1627032908,
                "seq": 82995908,
                "isMessageSender": True,
                "messageStatus": 2,
                "messageType": 2,
                "msgID": "144115261247181295-1627032907-3212347662",
                "receiverUserID": reciver,
                "senderUserID": sender,
                "messageBaseElements": {
                    "data": "{\"type\":100001,\"content\":\"问诊结束\"}",
                    "elementType": 2
                }
            }
        ]
    })


def getAdviceMedical(request):
    result = {}
    result.setdefault("isExecute", "1")
    result.setdefault("prescriptionUrl", "https://www.gjtool.cn/pdfh5/git.pdf")

    userModel = {"userName": "王小木", "userAge": 20, "userGender": 1}
    result.setdefault("userModel", userModel)
    diagnoseInfoList = {"diagnoseType": 1, "diagnoseName": "恶行肿瘤", "diagnoseCode": "AO1"}
    result.setdefault("diagnoseInfoList", diagnoseInfoList)
    drugsList = []
    result.setdefault("drugsList", drugsList)

    for i in range(0, 10):
        item = {
            "specificationName": "依托考昔片",
            "totalQuantity": 2,
            "packingUnitName": "片",
            "unitQuantity": "每次60mg",
            "frequencyName": 1,
            "usageName": "口服",
            "useDays": 3,
            "announcements": "饭后半小时服用"
        }
        drugsList.append(item)

    return createSuccessResult(result)


# 检查检验单数据保存
@csrf_exempt
def addImgUrl(request):
    # medicalAdviceImg = request.POST.get("medicalAdviceImg")
    # print("========================")
    # print(medicalAdviceImg)
    # print("========================")
    return createFailResult("")


import os


@csrf_exempt
def uplodFile(request):
    print("111111")
    if request.method == "POST":
        uf = UserForm(request.POST, request.FILES)
        if uf.is_valid():
            filename = uf.cleaned_data['filename']
            path = settings.MEDIA_ROOT + "/files/" + str(filename)
            print(path)
            if os.path.exists(path):
                # file = open(path, 'w')
                os.remove(path)
                print("删除成功")
            else:
                print("无改文件")
            # # 写入数据库
            f = Upload()
            f.file_path = filename
            f.save()
            path = str(f.file_path)
            host = '{scheme}://{host}'.format(scheme=request.scheme,
                                              host=request.get_host())
            print(host)
            return JsonResponse({"code": 10000, 'msg': '文件上传成功', 'data': host + "/media/" + path})

        return JsonResponse({"code": 1, 'msg': '文件上传失败'})
    else:
        return JsonResponse({"code": 2, 'msg': '文件上传失败'})
